﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Sample.JwtBearer.Api.Data;

public class RefreshToken
{
    [Key]
    [StringLength(32)]
    public string Id { get; set; } = string.Empty;

    [Required]
    [StringLength(32)] //128
    public string JwtId { get; set; } = string.Empty;

    [Required]
    [StringLength(256)]
    public string Token { get; set; } = string.Empty;

    [Required]
    [StringLength(32)]
    public string AccessTokenMd5 { get; set; } = string.Empty;

    /// <summary>
    /// 是否使用，一个RefreshToken只能使用一次
    /// </summary>
    [Required]
    public bool Used { get; set; }

    /// <summary>
    /// 是否失效。修改用户重要信息时可将此字段更新为true，使用户重新登录
    /// </summary>
    [Required]
    public bool Invalidated { get; set; }

    [Required]
    public DateTime CreationTime { get; set; }

    [Required]
    public DateTime ExpiryTime { get; set; }

    [Required]
    [StringLength(32)]
    public string UserId { get; set; } = string.Empty;

    [Required]
    [ForeignKey(nameof(UserId))]
    public AppUser User { get; set; } = new AppUser();
}